package logic

import (
	"context"
	"technician_srv/model/mysql"

	"technician_srv/internal/svc"
	"technician_srv/technician"

	"github.com/zeromicro/go-zero/core/logx"
)

type InsertTechnicianLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewInsertTechnicianLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InsertTechnicianLogic {
	return &InsertTechnicianLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *InsertTechnicianLogic) InsertTechnician(in *technician.InsertTechnicianRequest) (*technician.InsertTechnicianResponse, error) {
	// todo: add your logic here and delete this line
	m := mysql.Technician{
		Name:   in.Name,
		Cover:  int(in.Cover),
		Mobile: in.Mobile,
		Age:    int(in.Age),
		City:   int(in.City),
	}

	err := m.InsertTechnician()
	if err != nil {
		return nil, err
	}

	return &technician.InsertTechnicianResponse{Id: int64(m.ID)}, nil
}
